import * as collectionService from '../service/collections';

export default {

  namespace: 'collections',

  state: {
    hotImglist: [],
    isloading: false,
  },

  effects: {
    *queryInitHot({ payload }, { call, put }) {
      const rsp = yield call(collectionService.hotList, payload);
      console.log(rsp);
      //这边用来控制
      if(rsp.ret_pagecurrent > rsp.ret_pagecount){
        console.log("暂停咯")
        yield put({ type: 'hotDataList', payload: { hotImglist: [],isloading: false } });
      } else {
        console.log("开始咯")
        yield put({ type: 'hotDataList', payload: { hotImglist: rsp.ret_msg,isloading: true } });
      }
      
    },
  },

  reducers: {
    hotDataList(state, { payload: { hotImglist,isloading } }) {
      hotImglist =state.hotImglist.concat(hotImglist);
      return {
        ...state,
        hotImglist,
        isloading
      }
    },
    saveStatistic(state, { payload: { id, data } }) {
      return {
        ...state,
        statistic: {
          ...state.statistic,
          [id]: data,
        },
      }
    },
  },
};
